/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager;

import br.com.deployment.entidade.registroimovel.Operacao;
import br.com.deployment.message.Msg;
import br.com.deployment.servico.OperacaoServico;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

/**
 *
 * @author roniere
 */
@ManagedBean
@ViewScoped
public class ManagerOperacao implements Serializable{
    
    @EJB
    OperacaoServico operacaoServico;
    
    private Operacao operacao;

    @PostConstruct
    public void init() {
        this.operacao = new Operacao();
    }
    
    public void criar(){
        operacaoServico.salvar(operacao);
        Msg.messagemInfo("operação salva com sucesso.");
    }


    public Operacao getOperacao() {
        return operacao;
    }

    public void setOperacao(Operacao operacao) {
        this.operacao = operacao;
    }
    private List<Operacao> lstoperacao;
  
     public List<Operacao> completeOperacao(String query) {  
        List<Operacao> bd = new ArrayList<Operacao>();  
        
        Operacao operacao = new Operacao();
        operacao.setTipo(query);
        bd = operacaoServico.findOperacao(operacao);
        return bd;  
    } 
     
      public SelectItem[] selectItemOperacao() {
        List<Operacao> lstOpe = operacaoServico.findOperacao(operacao);
        SelectItem[] items = new SelectItem[lstOpe.size()];
        int i = 0;
        Operacao operacao = new Operacao();
        for (Operacao operacao1 : lstOpe) {
            items[i++] = new SelectItem(operacao1);
        }
        return items;
    }
    
    public void redirect(String string) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerImovel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    
}
